package de.dis2011;

import de.dis2011.data.*;

import java.sql.Connection;

import de.dis2011.data.DB2ConnectionManager;

/**
 * Hauptklasse
 */
public class Main
{

    /**
     * Startet die Anwendung
     */
    public static void main(String[] args)
    {
        showMainMenu();
    }

    /**
     * Zeigt das Hauptmenü
     */
    public static void showMainMenu()
    {
        // Menüoptionen
        final int MENU_ARTICLE = 0;
        final int MENU_SHOP = 1;
        final int QUIT = 2;

        // Erzeuge Menü
        Menu mainMenu = new Menu("Hauptmenü");
        mainMenu.addEntry("Artikel", MENU_ARTICLE);
        mainMenu.addEntry("Shop", MENU_SHOP);
        mainMenu.addEntry("Beenden", QUIT);

        // Verarbeite Eingabe
        while (true)
        {
            int response = mainMenu.show();

            switch (response)
            {
            case MENU_ARTICLE:
                showArticleMenu();
                break;
            case MENU_SHOP:
                showShopMenu();
                break;
            case QUIT:
                return;
            }
        }
    }

    /**
     * Zeige das Menü der Artikel
     */
    public static void showArticleMenu()
    {
        final int SHOW_ARTICLE = 0;
        final int SHOW_ALL_ARTICLE = 1;
        final int BACK = 2;

        Menu articleMenu = new Menu("Artikel");
        articleMenu.addEntry("Zeige Artikel", SHOW_ARTICLE);
        articleMenu.addEntry("Zeige alle Artikel", SHOW_ALL_ARTICLE);
        articleMenu.addEntry("Zurück zum Hauptmenü", BACK);

        while (true)
        {
            int response = articleMenu.show();

            switch (response)
            {
            case SHOW_ARTICLE:
                showArticle();
                break;
            case SHOW_ALL_ARTICLE:
                showAllArticle();
                break;
            case BACK:
                return;
            }
        }
    }

    /**
     * Zeigt das Menü der Shops
     */
    public static void showShopMenu()
    {
        final int SHOW_SHOP = 0;
        final int SHOW_ALL_SHOP = 1;
        final int BACK = 2;

        Menu articleMenu = new Menu("Shops");
        articleMenu.addEntry("Zeige Shop", SHOW_SHOP);
        articleMenu.addEntry("Zeige alle Shops", SHOW_ALL_SHOP);
        articleMenu.addEntry("Zurück zum Hauptmenü", BACK);

        while (true)
        {
            int response = articleMenu.show();

            switch (response)
            {
            case SHOW_SHOP:
                showShop();
                break;
            case SHOW_ALL_SHOP:
                showAllShop();
                break;
            case BACK:
                return;
            }
        }
    }

    /**
     * Zeigt einen Artikel
     */
    public static void showArticle()
    {
        article a = new article();
        a.setArticleid(FormUtil.readInt("articleid"));
        a.load(a.getArticleid());
        System.out.println("--");
    }

    /**
     * Zeigt alle Artikel
     */
    public static void showAllArticle()
    {
        article a = new article();
        a.loadAll();
        System.out.println("--");
    }

    /**
     * Zeigt einen Shop
     */
    public static void showShop()
    {
        shop s = new shop();
        s.setShopid(FormUtil.readInt("shopid"));
        s.load(s.getShopid());
        System.out.println("--");
    }

    /**
     * Zeigt alle Shops
     */
    public static void showAllShop()
    {
        shop s = new shop();
        s.loadAll();
        System.out.println("--");
    }
}
